package com.douyinkan.controller;

import com.douyinkan.dto.TagDTO;
import com.douyinkan.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/tags")
public class TagController {
    
    @Autowired
    private TagService tagService;
    
    @GetMapping
    public ResponseEntity<List<TagDTO>> getAllTags() {
        List<TagDTO> tags = tagService.getAllTags();
        return ResponseEntity.ok(tags);
    }
    
    @PostMapping
    public ResponseEntity<TagDTO> createTag(@RequestBody TagRequest request) {
        TagDTO tag = tagService.createTag(request.getName());
        if (tag != null) {
            return ResponseEntity.ok(tag);
        } else {
            return ResponseEntity.badRequest().build();
        }
    }
    
    // 内部类用于处理请求体
    public static class TagRequest {
        private String name;
        
        public String getName() {
            return name;
        }
        
        public void setName(String name) {
            this.name = name;
        }
    }
}